package com.kbt.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.*;
import com.google.gson.Gson;
import com.kbt.adapter.GoodInfoAdapter;
import com.kbt.base.BaseApplication;
import com.kbt.commont.Constants;
import com.kbt.listener.ClickActStartActForResultListener;
import com.kbt.model.data.BaseBean;
import com.kbt.net.RequestManager;
import com.kbt.util.data.StaticData;
import com.kbt.util.utils.LoadingDialog;
import com.kbt.util.utils.MD5Utils;
import com.kbt.util.utils.SharePreferenceUtils;
import com.kbt.util.utils.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class CheckActivity extends Activity implements RequestManager.ResponseInterface{

    private BaseBean baseBean;
    private RequestManager mRequestManager;
    private Map<String,String> postMap=null;
    private SharePreferenceUtils share;
    private LoadingDialog mProgress;
    private GoodInfoAdapter goodInfoAdapter;
    private ListView listview;
    private List<String> imageList = new ArrayList<String>();


    /***
     * @param savedInstanceState
     */

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.check_bao_gao);
        this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_return_btn);

        //设置返回按钮事件,关闭当前Activity，返回数据
        ImageView returnImg = (ImageView) findViewById(R.id.return_btn);
        returnImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //不创建地址
                setResult(RESULT_CANCELED, null);
                BaseApplication.getInstance().removeActivity(CheckActivity.this);
                finish();
            }
        });

        TextView appTitleView = (TextView) findViewById(R.id.center_title);
        appTitleView.setText("检测报告");

        BaseApplication.getInstance().addActivity(this);
        mRequestManager = new RequestManager();
        mRequestManager.setResponseListener(this);
        postMap = new HashMap<String, String>();
        share = new SharePreferenceUtils(CheckActivity.this);
        listview = (ListView) findViewById(R.id.checkListView);
        String image = getIntent().getStringExtra("zhiJianImage");
        String zhiJianImage[] = image.split(",");
        for(int i=0;i<zhiJianImage.length;i++){
            if (!",".equals(zhiJianImage[i])) {
                imageList.add(zhiJianImage[i]);
            }
        }
        goodInfoAdapter = new GoodInfoAdapter(this,imageList);
        listview.setAdapter(goodInfoAdapter);
    }

    /**
     * 重写启动方法
     */
    @Override
    protected void onStart() {
        super.onStart();
    }



    @Override
    public <T> void successResponse(T parsedGSON, int tag) {
        stopProgress();

    }

    @Override
    public void errorResonse(String retmeg, int tag) {
        stopProgress();
        Toast.makeText(CheckActivity.this,R.string.noWangluo,Toast.LENGTH_SHORT).show();
    }
    /**
     * progressDialog的展示
     */
    public void showProgress() {
        if (mProgress == null) {
            mProgress = new LoadingDialog(CheckActivity.this,"");
            mProgress.setCancelable(true);
            mProgress.show();

        } else {
            if (mProgress.isShowing()) {
                stopProgress();
            } else {
                mProgress.show();
            }
        }
    }


    /**
     * progressDialog的消失
     */
    public void stopProgress() {
        if (mProgress != null) {
            mProgress.dismiss();
            mProgress = null;
        }
    }
}
